package com.sxkf.template.mq;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sxkf.template.entity.SpellOut;
import com.sxkf.template.mapper.SpellOutMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class Consumer {

    @Resource
    private SpellOutMapper spellOutMapper;



    @RabbitListener(queues = "dq.delayed")
    @RabbitHandler
    public void recieve(Message message) {
        // 获取message的配置
        MessageProperties properties = message.getMessageProperties();
        // 获取消息主体
        String body = new String(message.getBody());
        log.info("接收到id：{}", body);
        SpellOut spellOut = spellOutMapper.selectById(body);
        log.info("拼团状态(0=未拼成，1=已拼成，2=已过期):{}", spellOut.getState());
        // 检查状态
        if (!spellOut.getState().equals("1")){
            log.info("拼团失败，修改订单状态");
            spellOut.setState("2");
            spellOutMapper.updateById(spellOut);
            return;
        }
        log.info("拼团成功，不管");

    }




}
